package com.uzhie.web.service;

import com.uzhie.web.bean.PageBean;
import com.uzhie.web.dao.JT_8702DAO;
import com.uzhie.exception.JT_8702Exception;
import com.uzhie.jt808.jt1078.entity.JT_8702;
import com.uzhie.web.module.Vehicle;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 用户service,封装与用户相关的服务操作
 *
 * Created by zhangdequan on 2018/7/12.
 */
@Service
public class JT_8702Service {

    @Autowired
    private JT_8702DAO jt_8702DAO;

    @Autowired
    private  VehicleService vehicleService;
    /**
     * 添加司机上下线记录
     * @param body
     * @throws JT_8702Exception
     */
    public void addJT8702(byte[] body) throws JT_8702Exception{
        JT_8702 jt_8702 = new JT_8702();
        jt_8702.ReadFromBytes(body);
        //查询车辆信息
        Vehicle vehicle = vehicleService.selectByNumber(jt_8702.getSimNumber());
        jt_8702.setDepartId(vehicle.getDepartId());
        jt_8702.setDepartName(vehicle.getDepartName());
        int t = jt_8702DAO.insert(jt_8702);
        if (t != 1) throw new JT_8702Exception(JT_8702Exception.Status.INSERT_ERROR);
    }

    /**
     * 根据条件查询上下线数据
     * @param userId
     * @param status
     * @param beginTime
     * @param endTime
     * @param driver
     * @param org_name
     * @param pageBean
     * @return
     */
    public List<Map> selectAllRecordByCondition(String userId, int status, String beginTime, String endTime, String driver, String org_name, PageBean pageBean){
        return jt_8702DAO.selectAllRecordByCondition(userId,status, beginTime, endTime, driver, org_name,pageBean.getRowBounds());
    }




}


